package model.abstractClass

import common.Direction
import common.doDirectionAction
import model.View
import model.inter.Moveable
import java.awt.Rectangle


abstract class MoveableView(override  var x: Int, override var y: Int): View(x=x,y=y),Moveable {




    override fun getNextRect(direction: Direction): Rectangle {

        return direction.doDirectionAction(
                {Rectangle(x,y-speed,width,height)},
                {Rectangle(x,y+speed,width,height) },
                { Rectangle(x-speed,y,width,height) },
                { Rectangle(x+speed,y,width,height) })
    }



    override fun move(direction:Direction){

        //这里表示前进的一个操作；
        if(direction == mCurrentDirection){
            direction.doDirectionAction(
                    { y-=speed },{y+=speed},{x-=speed},{x+=speed}
            )
        }
        //对其进行一个校验；
        checkPostionValid()
    }

    //改变方向；
    fun changeDirection(direction:Direction){
        if(direction != mCurrentDirection){
            //这里我们要做的一个操作就是调整方向的一个逻辑；
            mCurrentDirection=direction
        }
    }

}